import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';

//1. 问题：如何导入自定义配置文件？
//1.1 导入自定义配置文件对象
import userConfig from './config';

export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>;

  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1648661855596_6906';

  // add your egg config in here
  config.middleware = [];

  config.cors = {
    //同意所有源 的跨域
    origin: () => '*',
    allowMethods: 'GET,POST,PUT,DELETE,HEAD,PATCH',
    credentials: true
  };

  config.security = {
    csrf: {
      enable: false
    }
  };

  // add your special config in here
  const bizConfig = {
    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`
  };

  // the return config will combines to EggAppConfig
  return {
    //1.2 在此处拼接自定义配置文件对象 这样就完成导入
    //    写法: config.APP_KEY
    ...userConfig,
    ...config,
    ...bizConfig
  };
};
